local hx__wushuang = fk.CreateSkill {
  name = "hx__wushuang",
  tags = { Skill.Compulsory },
}


hx__wushuang:addEffect(fk.DamageCaused, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not ( target == player and player:hasSkill(hx__wushuang.name) and data.by_user
    and data.card and table.contains({ "slash", "duel" }, data.card.trueName) ) then
      return false
    end
    local effectEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
    if effectEvent then
      local effectData = effectEvent.data
      if effectData.card.trueName == "slash" then
        return not table.find(effectData.cardsResponded or {},
          function(card) return card.trueName == "jink"
        end)
      elseif effectData.card.trueName == "duel" then
        return #player.room.logic:getEventsByRule(GameEvent.RespondCard, 1, function(e)
          local reponseData = e.data
          return reponseData.card.trueName == "slash" and reponseData.responseToEvent == effectData
        end, nil, Player.HistoryTurn) == 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, hx__wushuang.name, "offensive")
    player:broadcastSkillInvoke(hx__wushuang.name, math.random(1, 2))
    data:changeDamage(1)
  end,
})

---@type TrigSkelSpec<AimFunc>
local hx__wushuangSpec = {
  on_use = function(self, event, target, player, data)
    local to = (event == fk.TargetConfirmed and data.card.trueName == "duel") and data.from or data.to
    player.room:notifySkillInvoked(player, hx__wushuang.name, "offensive")
    player:broadcastSkillInvoke(hx__wushuang.name, math.random(1, 2))
    data:setResponseTimes(2, to)
  end,
}

hx__wushuang:addEffect(fk.TargetSpecified, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__wushuang.name) and table.contains({ "slash", "duel" }, data.card.trueName)
  end,
  on_use = hx__wushuangSpec.on_use,
})

hx__wushuang:addEffect(fk.TargetConfirmed, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__wushuang.name) and data.card.trueName == "duel"
  end,
  on_use = hx__wushuangSpec.on_use,
})

return hx__wushuang
